package com.seteam.collabcrossword.windows;

import com.seteam.collabcrossword.Clue;
import net.miginfocom.swing.MigLayout;

import javax.swing.*;
import javax.swing.border.EtchedBorder;
import java.awt.*;

public class CluesPane extends JPanel{
    private JTextArea cluesAcross;
    private JTextArea cluesDown;
    private JScrollPane scrollPaneAcross;
    private JScrollPane scrollPaneDown;
    private java.util.List<Clue> across;
    private java.util.List<Clue> down;
    private MigLayout migLayout;

    public CluesPane(final java.util.List<Clue> across, final java.util.List<Clue> down) {
        super();
        cluesAcross = new JTextArea();
        cluesDown = new JTextArea();
        migLayout = new MigLayout("",                 // Layout Constraints
                "[grow][][grow]",   // Column constraints
                "[][shrink 1]");
        this.across = across;
        this.down = down;
        init();
    }

    private void init() {
        this.setLayout(migLayout);
        cluesAcross.setEditable(false);
        cluesDown.setEditable(false);

        StringBuilder acrossCluesBuilder = new StringBuilder();
        StringBuilder downCluesBuilder = new StringBuilder();

        for(final Clue clue: across) {
            acrossCluesBuilder.append(clue.getID()).append('-')
                    .append(clue.getStatement()).append('\n');
        }

        for(final Clue clue: down) {
            downCluesBuilder.append(clue.getID()).append('-')
                    .append(clue.getStatement()).append('\n');
        }


        scrollPaneAcross = new JScrollPane(cluesAcross);
        scrollPaneDown = new JScrollPane(cluesDown);
        
        scrollPaneAcross.setPreferredSize(new Dimension(270, 200));
        scrollPaneDown.setPreferredSize(new Dimension(270, 200));
        
        this.add(scrollPaneAcross, "wrap");
        this.add(scrollPaneDown);
        cluesAcross.setText(acrossCluesBuilder.toString());
        cluesDown.setText(downCluesBuilder.toString());

        this.setPreferredSize(new Dimension(270, 400));
        this.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
        //clues.setRows(this.getHeight());

        //setVisible(true);
    }
}
